<template>
    <el-dialog v-dialogDrag v-if="popenevTVisible" title="二维码" :visible.sync="popenevTVisible" width="450px" >
        <img :src="imageUrl" alt="" srcset="" style="width: 400px; height: 400px;" />
    </el-dialog>
</template>

<script>
import request from '@/utils/request'
export default {
    data () {
        return {
            popenevTVisible: false,
            //promise 状态
            promiseStatus: null,
            imageUrl: ''
        }
    },
    methods: {
        show(callback, config)
        {
            console.log(callback, 'callback')
            if (callback)
            {
                this.getQrcode(callback)
            }
            this.popenevTVisible = true;
            // 创建promise
            return new Promise((resolve, reject) => {
                this.promiseStatus = {
                    resolve,
                    reject
                }
            })
        },
        getQrcode(object)
        {
            let requestParams = {
                url: object.path,
                method: object.methodName,
                responseType: 'blob'
            }
            if (object.methodName.toLowerCase() == "post")
            {
                requestParams.data = object.params
            }
            else
            {
                requestParams.params = object.params
            }

            //执行请求
            request(requestParams).then(res => {
                console.log(res, 'res')
                if (res instanceof Blob)
                {
                    let blob = new Blob([res], { type: "image/jpeg" });
                    // 图片url地址
                    this.imageUrl = URL.createObjectURL(blob);
                }
                else if (res.data instanceof Blob)
                {
                    let blob = new Blob([res.data], { type: "image/jpeg" });
                    // 图片url地址
                    this.imageUrl = URL.createObjectURL(blob);
                }
            })
        }
    }
}
</script>

<style>

</style>